package com.alibaba.dubbo.remoting.interceptor;

import java.util.List;

import com.alibaba.dubbo.remoting.Interceptor;

public class InterceptorSupport {

	/**
	 * 多个interceptor自动组成过滤链
	 * @param filters
	 * @return
	 */
	public static Interceptor build(Interceptor [] interceptors){
		if(interceptors != null && interceptors.length == 0) return new InterceptorWrapperChain(null);
		InterceptorWrapper wrapper = new InterceptorWrapper();
		for(int i = 0;i<interceptors.length;i++){
			Interceptor f = interceptors[i];
			if(f == null) continue;
			wrapper.add(f);
		}
		
		return wrapper;
	}
	
	public static Interceptor build(List<Interceptor> interceptors){
		if(interceptors == null || interceptors.size() == 0) return new InterceptorWrapper(); 
		return build(interceptors.toArray(new Interceptor[interceptors.size()]));
	}
}
